﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lawyer.Web.Admin
{
    public partial class admin_customlist : System.Web.UI.Page
    {
        public string type0 = "";
        public string type1 = "";
        public string typeall = "";
        Lawyer.BLL.CustomInfo bll = new Lawyer.BLL.CustomInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //btnDelete.Attributes.Add("onclick", "return confirm(\"你确认要删除吗？\")");
                BindData();
            }
            if (gridView.HeaderRow != null)
                gridView.HeaderRow.TableSection = TableRowSection.TableHeader;
        }

        public void BindData()
        {
            int type = -1;
            try
            {
                type = Request["type"] == null ? -1 : Int32.Parse(Request["type"]);
            }
            catch
            {
                type = -1;
            }
            string strWhere = "";
            string UserID = Session["UserID"].ToString();
            if (type == 0)
            {
                strWhere = " CreatedBy = '" + UserID + "' AND Type = 0 ";
                type0 = "current";
            }
            else if (type == 1)
            {
                strWhere = " CreatedBy != '" + UserID + "' or Type != 0 ";
                type1 = "current";
            }
            else
            {
                strWhere = "";
                typeall = "current";
            }
            List<Lawyer.Model.CustomInfo> list = bll.GetModelList(strWhere.ToString());

            //if (txtKeyword.Text.Trim() != "")
            //{      
            //    #warning 代码生成警告：请修改 keywordField 为需要匹配查询的真实字段名称
            //    //strWhere.AppendFormat("keywordField like '%{0}%'", txtKeyword.Text.Trim());
            //}            


            gridView.DataSource = list;
            gridView.DataBind();
        }

        #region gridView


        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_OnRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                //e.Row.Cells[0].Text = "<input id='Checkbox2' type='checkbox' onclick='CheckAll()'/><label></label>";
            }
        }
        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // e.Row.Attributes.Add("style", "background:#FFF");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //LinkButton linkbtnDel = (LinkButton)e.Row.FindControl("LinkButton1");
                //linkbtnDel.Attributes.Add("onclick", "return confirm(\"你确认要删除吗\")");

                //object obj1 = DataBinder.Eval(e.Row.DataItem, "Levels");
                //if ((obj1 != null) && ((obj1.ToString() != "")))
                //{
                //    e.Row.Cells[1].Text = obj1.ToString();
                //}

            }
        }

        protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //#warning 代码生成警告：请检查确认真实主键的名称和类型是否正确
            //int ID = (int)gridView.DataKeys[e.RowIndex].Value;
            //bll.Delete(ID);
            //gridView.OnBind();
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }

        #endregion

        protected void btnAddCustom_Click(object sender, EventArgs e)
        {
            Response.Redirect("admin_customadd.aspx");
        }
    }
}
